package com.study.demo.gsbean.demo1;

import org.springframework.beans.factory.BeanClassLoaderAware;

import java.io.InputStream;

/**
 * @author: elvin
 * @time: 2019-04-17 14:28
 * @desc:
 **/
public class MyBeanClassLoaderAware implements BeanClassLoaderAware {

    private ClassLoader classLoader ;

    public void setBeanClassLoader(ClassLoader classLoader) {
        this.classLoader = classLoader;
    }

    public void printResource(String path){
        try{
            InputStream inputStream = classLoader.getResourceAsStream(path);
            int length = inputStream.available();
            byte[] bytes = new byte[length];
            int read = inputStream.read(bytes, 0, length);
            String str = new String(bytes);
            System.out.println(str);
        }
        catch(Exception e){
            System.out.println(e.getMessage());
        }
    }
}
